package com.hxx.day2.action;

import org.junit.Test;

import java.util.List;

public class TestDemo {
    /**
     * 二维数组
     * @param args
     */
    public static void main(String... args) {
        int[][] arr = {{1},{2,3},{4,5,6}};
        for (int index = 0; index < arr.length; index++) {
            for (int n=0;n<arr[index].length;n++){
                System.out.println("arr["+index+"]["+n+"]="+arr[index][n]);
            }
        }
    }

    @Test //高维创建二维数组，列不确定
    public void test1(){
        int[][] arr = new int[2][];
        //使用前必须确定列
        arr[0] = new int[1];
        arr[1] = new int[2];
        //写元素element
        arr[0][0] = 10;
        arr[1][0] = 20;
        arr[1][1] = 30;
        //循环
        for (int rows = 0; rows < arr.length; rows++) {
            for (int cols = 0; cols < arr[rows].length; cols++) {
                System.out.println("arr["+rows+"]["+cols+"]="+arr[rows][cols]);
            }
        }
    }
}
























